package com.noshufou.android.su.util;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.util.Log;
import com.noshufou.android.su.provider.PermissionsProvider.Apps;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

public class BackupUtil
{
  private static final String TAG = "Su.BackupUtil";

  private static boolean backupApps(Context paramContext, XmlSerializer paramXmlSerializer)
  {
    Cursor localCursor = paramContext.getContentResolver().query(PermissionsProvider.Apps.CONTENT_URI, null, null, null, null);
    int i;
    if (localCursor == null)
      i = 0;
    while (true)
    {
      return i;
      if (localCursor.getCount() == 0)
      {
        localCursor.close();
        i = 1;
        continue;
      }
      try
      {
        paramXmlSerializer.startTag("", "apps");
        while (true)
        {
          if (!localCursor.moveToNext())
          {
            paramXmlSerializer.endTag("", "apps");
            if (localCursor != null)
              localCursor.close();
            i = 1;
            break;
          }
          paramXmlSerializer.startTag("", "app");
          paramXmlSerializer.attribute("", "package", localCursor.getString(localCursor.getColumnIndex("package")));
          paramXmlSerializer.attribute("", "name", localCursor.getString(localCursor.getColumnIndex("name")));
          paramXmlSerializer.attribute("", "exec_uid", localCursor.getString(localCursor.getColumnIndex("exec_uid")));
          paramXmlSerializer.attribute("", "exec_cmd", localCursor.getString(localCursor.getColumnIndex("exec_cmd")));
          paramXmlSerializer.attribute("", "allow", localCursor.getString(localCursor.getColumnIndex("allow")));
          String str1 = localCursor.getString(localCursor.getColumnIndex("notifications"));
          if (str1 != null)
            paramXmlSerializer.attribute("", "notifications", str1);
          String str2 = localCursor.getString(localCursor.getColumnIndex("logging"));
          if (str2 != null)
            paramXmlSerializer.attribute("", "logging", str2);
          paramXmlSerializer.endTag("", "app");
        }
      }
      catch (IOException localIOException)
      {
        Log.e("Su.BackupUtil", "Problem backing up apps", localIOException);
        if (localCursor != null)
          localCursor.close();
        i = 0;
        continue;
      }
      finally
      {
        if (localCursor != null)
          localCursor.close();
      }
    }
    throw localObject;
  }

  private static boolean backupPrefs(Context paramContext, XmlSerializer paramXmlSerializer)
    throws IOException
  {
    Map localMap = PreferenceManager.getDefaultSharedPreferences(paramContext).getAll();
    if (localMap.isEmpty())
      return true;
    paramXmlSerializer.startTag("", "prefs");
    Iterator localIterator = localMap.keySet().iterator();
    String str1;
    String str2;
    do
    {
      if (!localIterator.hasNext())
      {
        paramXmlSerializer.endTag("", "prefs");
        break;
      }
      str1 = (String)localIterator.next();
      str2 = "unknown";
    }
    while ((!str1.startsWith("pref_")) && (!str1.equals("pin")));
    Object localObject = localMap.get(str1);
    if ((localObject instanceof Boolean))
    {
      str2 = "boolean";
      label127: paramXmlSerializer.startTag("", str2);
      paramXmlSerializer.attribute("", "name", str1);
      if (!str2.equals("string"))
        break label232;
      paramXmlSerializer.text(String.valueOf(localObject));
    }
    while (true)
    {
      paramXmlSerializer.endTag("", str2);
      break;
      if ((localObject instanceof String))
      {
        str2 = "string";
        break label127;
      }
      if ((localObject instanceof Integer))
      {
        str2 = "int";
        break label127;
      }
      if (!(localObject instanceof Long))
        break label127;
      str2 = "long";
      break label127;
      label232: paramXmlSerializer.attribute("", "value", String.valueOf(localObject));
    }
  }

  // ERROR //
  public static boolean makeBackup(Context paramContext)
  {
    // Byte code:
    //   0: iconst_0
    //   1: istore_1
    //   2: invokestatic 191	android/util/Xml:newSerializer	()Lorg/xmlpull/v1/XmlSerializer;
    //   5: astore_2
    //   6: new 193	java/io/FileOutputStream
    //   9: dup
    //   10: new 195	java/io/File
    //   13: dup
    //   14: new 197	java/lang/StringBuilder
    //   17: dup
    //   18: invokestatic 203	android/os/Environment:getExternalStorageDirectory	()Ljava/io/File;
    //   21: invokevirtual 207	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   24: invokestatic 165	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   27: invokespecial 210	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   30: ldc 212
    //   32: invokevirtual 216	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   35: invokevirtual 219	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   38: invokespecial 220	java/io/File:<init>	(Ljava/lang/String;)V
    //   41: invokespecial 223	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   44: astore_3
    //   45: aload_2
    //   46: aload_3
    //   47: ldc 225
    //   49: invokeinterface 229 3 0
    //   54: aload_2
    //   55: aconst_null
    //   56: iconst_1
    //   57: invokestatic 232	java/lang/Boolean:valueOf	(Z)Ljava/lang/Boolean;
    //   60: invokeinterface 236 3 0
    //   65: aload_2
    //   66: ldc 238
    //   68: iconst_1
    //   69: invokeinterface 242 3 0
    //   74: aload_2
    //   75: ldc 45
    //   77: ldc 244
    //   79: invokeinterface 53 3 0
    //   84: pop
    //   85: aload_0
    //   86: aload_2
    //   87: invokestatic 246	com/noshufou/android/su/util/BackupUtil:backupApps	(Landroid/content/Context;Lorg/xmlpull/v1/XmlSerializer;)Z
    //   90: pop
    //   91: aload_0
    //   92: aload_2
    //   93: invokestatic 248	com/noshufou/android/su/util/BackupUtil:backupPrefs	(Landroid/content/Context;Lorg/xmlpull/v1/XmlSerializer;)Z
    //   96: istore 12
    //   98: aload_2
    //   99: ldc 45
    //   101: ldc 244
    //   103: invokeinterface 60 3 0
    //   108: pop
    //   109: aload_2
    //   110: invokeinterface 251 1 0
    //   115: aload_2
    //   116: invokeinterface 254 1 0
    //   121: aload_3
    //   122: invokevirtual 255	java/io/FileOutputStream:close	()V
    //   125: iload 12
    //   127: istore_1
    //   128: iload_1
    //   129: ireturn
    //   130: astore 4
    //   132: ldc 8
    //   134: ldc_w 257
    //   137: aload 4
    //   139: invokestatic 96	android/util/Log:e	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   142: pop
    //   143: goto -15 -> 128
    //   146: astore 6
    //   148: ldc 8
    //   150: ldc_w 259
    //   153: aload 6
    //   155: invokestatic 96	android/util/Log:e	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   158: pop
    //   159: goto -31 -> 128
    //   162: astore 8
    //   164: ldc 8
    //   166: ldc_w 261
    //   169: aload 8
    //   171: invokestatic 96	android/util/Log:e	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   174: pop
    //   175: goto -47 -> 128
    //   178: astore 8
    //   180: goto -16 -> 164
    //   183: astore 6
    //   185: goto -37 -> 148
    //   188: astore 4
    //   190: goto -58 -> 132
    //
    // Exception table:
    //   from	to	target	type
    //   6	45	130	java/lang/IllegalArgumentException
    //   6	45	146	java/lang/IllegalStateException
    //   6	45	162	java/io/IOException
    //   45	125	178	java/io/IOException
    //   45	125	183	java/lang/IllegalStateException
    //   45	125	188	java/lang/IllegalArgumentException
  }

  private static int restoreApps(Context paramContext, XmlPullParser paramXmlPullParser)
    throws XmlPullParserException, IOException
  {
    int i = 0;
    PackageManager localPackageManager = paramContext.getPackageManager();
    ContentResolver localContentResolver = paramContext.getContentResolver();
    int j = paramXmlPullParser.getEventType();
    while (true)
    {
      if ((j == 1) || ((j == 3) && (paramXmlPullParser.getName().equalsIgnoreCase("apps"))))
        return i;
      String str;
      if ((j == 2) && (paramXmlPullParser.getName().equalsIgnoreCase("app")))
        str = paramXmlPullParser.getAttributeValue("", "package");
      try
      {
        int k = localPackageManager.getApplicationInfo(str, 0).uid;
        ContentValues localContentValues = new ContentValues();
        localContentValues.put("uid", Integer.valueOf(k));
        for (int m = 0; ; m++)
        {
          if (m >= paramXmlPullParser.getAttributeCount())
          {
            localContentResolver.insert(PermissionsProvider.Apps.CONTENT_URI, localContentValues);
            i++;
            j = paramXmlPullParser.next();
            break;
          }
          localContentValues.put(paramXmlPullParser.getAttributeName(m), paramXmlPullParser.getAttributeValue(m));
        }
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException)
      {
        while (true)
          Log.i("Su.BackupUtil", "package" + str + " not installed, skipping restore");
      }
    }
  }

  // ERROR //
  public static int restoreBackup(Context paramContext)
  {
    // Byte code:
    //   0: bipush 255
    //   2: istore_1
    //   3: invokestatic 338	android/util/Xml:newPullParser	()Lorg/xmlpull/v1/XmlPullParser;
    //   6: astore_2
    //   7: iconst_0
    //   8: istore_3
    //   9: new 340	java/io/FileInputStream
    //   12: dup
    //   13: new 195	java/io/File
    //   16: dup
    //   17: new 197	java/lang/StringBuilder
    //   20: dup
    //   21: invokestatic 203	android/os/Environment:getExternalStorageDirectory	()Ljava/io/File;
    //   24: invokevirtual 207	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   27: invokestatic 165	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   30: invokespecial 210	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   33: ldc 212
    //   35: invokevirtual 216	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   38: invokevirtual 219	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   41: invokespecial 220	java/io/File:<init>	(Ljava/lang/String;)V
    //   44: invokespecial 341	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   47: astore 4
    //   49: aload_2
    //   50: aload 4
    //   52: ldc 225
    //   54: invokeinterface 345 3 0
    //   59: aload_2
    //   60: invokeinterface 276 1 0
    //   65: istore 9
    //   67: goto +115 -> 182
    //   70: aload_2
    //   71: invokeinterface 318 1 0
    //   76: istore 9
    //   78: goto +104 -> 182
    //   81: aload_2
    //   82: invokeinterface 279 1 0
    //   87: ldc 47
    //   89: invokevirtual 282	java/lang/String:equalsIgnoreCase	(Ljava/lang/String;)Z
    //   92: ifeq +19 -> 111
    //   95: aload_2
    //   96: invokeinterface 318 1 0
    //   101: pop
    //   102: aload_0
    //   103: aload_2
    //   104: invokestatic 347	com/noshufou/android/su/util/BackupUtil:restoreApps	(Landroid/content/Context;Lorg/xmlpull/v1/XmlPullParser;)I
    //   107: istore_3
    //   108: goto -38 -> 70
    //   111: aload_2
    //   112: invokeinterface 279 1 0
    //   117: ldc 116
    //   119: invokevirtual 282	java/lang/String:equalsIgnoreCase	(Ljava/lang/String;)Z
    //   122: ifeq -52 -> 70
    //   125: aload_2
    //   126: invokeinterface 318 1 0
    //   131: pop
    //   132: aload_0
    //   133: aload_2
    //   134: invokestatic 351	com/noshufou/android/su/util/BackupUtil:restorePrefs	(Landroid/content/Context;Lorg/xmlpull/v1/XmlPullParser;)V
    //   137: goto -67 -> 70
    //   140: astore 7
    //   142: ldc 8
    //   144: ldc_w 353
    //   147: aload 7
    //   149: invokestatic 96	android/util/Log:e	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   152: pop
    //   153: goto +37 -> 190
    //   156: astore 5
    //   158: ldc 8
    //   160: ldc_w 353
    //   163: aload 5
    //   165: invokestatic 96	android/util/Log:e	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   168: pop
    //   169: goto +21 -> 190
    //   172: astore 5
    //   174: goto -16 -> 158
    //   177: astore 7
    //   179: goto -37 -> 142
    //   182: iload 9
    //   184: iconst_1
    //   185: if_icmpne +7 -> 192
    //   188: iload_3
    //   189: istore_1
    //   190: iload_1
    //   191: ireturn
    //   192: iload 9
    //   194: tableswitch	default:+-124 -> 70, 2:+-113->81
    //
    // Exception table:
    //   from	to	target	type
    //   49	137	140	org/xmlpull/v1/XmlPullParserException
    //   9	49	156	java/io/IOException
    //   49	137	172	java/io/IOException
    //   9	49	177	org/xmlpull/v1/XmlPullParserException
  }

  private static void restorePrefs(Context paramContext, XmlPullParser paramXmlPullParser)
    throws XmlPullParserException, IOException
  {
    SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(paramContext);
    SharedPreferences.Editor localEditor = localSharedPreferences.edit();
    localEditor.clear();
    int i = paramXmlPullParser.getEventType();
    if ((i == 1) || ((i == 3) && (paramXmlPullParser.getName().equalsIgnoreCase("prefs"))))
    {
      localEditor.commit();
      if ((localSharedPreferences.getBoolean("pref_pin", false)) && (!localSharedPreferences.contains("pin")))
        localSharedPreferences.edit().putBoolean("pref_pin", false).commit();
      return;
    }
    if (i == 2)
    {
      if (!paramXmlPullParser.getName().equalsIgnoreCase("boolean"))
        break label167;
      localEditor.putBoolean(paramXmlPullParser.getAttributeValue("", "name"), Boolean.parseBoolean(paramXmlPullParser.getAttributeValue("", "value")));
    }
    while (true)
    {
      i = paramXmlPullParser.next();
      break;
      label167: if (paramXmlPullParser.getName().equalsIgnoreCase("string"))
      {
        localEditor.putString(paramXmlPullParser.getAttributeValue("", "name"), paramXmlPullParser.nextText());
        continue;
      }
      if (paramXmlPullParser.getName().equalsIgnoreCase("int"))
      {
        localEditor.putInt(paramXmlPullParser.getAttributeValue("", "name"), Integer.parseInt(paramXmlPullParser.getAttributeValue("", "value")));
        continue;
      }
      if (!paramXmlPullParser.getName().equalsIgnoreCase("long"))
        continue;
      localEditor.putLong(paramXmlPullParser.getAttributeValue("", "name"), Long.parseLong(paramXmlPullParser.getAttributeValue("", "value")));
    }
  }
}

/* Location:           D:\Development\Decompile_Workspace\슈퍼유저-41\classes_dex2jar.jar
 * Qualified Name:     com.noshufou.android.su.util.BackupUtil
 * JD-Core Version:    0.6.0
 */